<template>
  <div>
    <!-- <el-button type="primary"
               plain
               size="small"
               @click="handle_add">新增</el-button> -->
    <el-table :data="table_data"
              v-loading="table_loading">
      <el-table-column type="index"
                       header-align="center"
                       align="center"
                       width="50"
                       label="序号">
      </el-table-column>
      <el-table-column prop="label"
                       header-align="center"
                       align="center"
                       label="名称">
      </el-table-column>
      <el-table-column prop="spec"
                       header-align="center"
                       align="center"
                       label="规格">
      </el-table-column>
      <el-table-column header-align="center"
                       align="center"
                       width="150"
                       label="操作">
        <template slot="header"
                  slot-scope="scope">
          <el-button type="primary"
                     plain
                     size="small"
                     @click="handle_add">新增</el-button>
        </template>
        <template slot-scope="scope">
          <el-button type="text"
                     size="small"
                     @click="handle_view(scope.row.bannerId)">查看</el-button>
          <el-button type="text"
                     size="small"
                     @click="handle_edit(scope.row.bannerId)">修改</el-button>
          <el-button type="text"
                     size="small"
                     @click="handle_delete(scope.row.bannerId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <categoryDialog ref="categoryDialog"
                    v-if="isCategoryDialog"
                    @close="isCategoryDialog = false"
                    @updateTable="getDataList"></categoryDialog>
  </div>
</template>

<script>
import categoryDialog from './category-dialog.vue'
import { treeDataTranslate } from '@/utils'

export default {
  components: { categoryDialog },
  data () {
    return {
      table_loading: false,
      pageIndex: 1,
      pageSize: 10,
      dataForm: {
        name: ""
      },
      table_data: [],
      isCategoryDialog: false
    }
  },
  activated () {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList () {
      this.table_loading = true
      this.$http({
        url: this.$http.adornUrl('/goods/category/list'),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({ data }) => {
        // if (data.code == 0) {
          console.log("data", data);
          this.table_data = data;
        // }
        this.table_loading = false
      })
    },
    // 新增
    handle_add () {
      this.isCategoryDialog = true;
      this.$nextTick(() => {
        this.$refs.categoryDialog.init(null, 'add');
      })
    },

    // 查看
    handle_view (id) {
      this.isCategoryDialog = true;
      this.$nextTick(() => {
        this.$refs.categoryDialog.init(id, 'view');
      })
    },
    // 修改
    handle_edit (id) {
      this.isCategoryDialog = true;
      this.$nextTick(() => {
        this.$refs.categoryDialog.init(id, 'edit');
      })
    },
    handle_delete (id) {
      this.$confirm(`确定对id=${id}]进行删除操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/banner/delete'),
          method: 'post',
          data: this.$http.adornData([id], false)
        }).then(({ data }) => {
          if (data.code == 0) {
            this.getDataList()
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.custom_img {
  width: 50px;
  height: 50px;
}
</style>